<template>
  <div class="container">
    <div class="app-container">
      <div class="left">
        <div class="left-main">
          <el-tree
            :data="data"
            :props="defaultProps"
            accordion
            highlight-current
            :indent="40"
            icon-class="el-icon-circle-plus-outline"
            @node-click="handleNodeClick"
          />
        </div>
      </div>
      <div class="right">
        <div class="top">
          <nav class="top-nav">
            <h3>机构信息</h3>
          </nav>
          <div class="top-main">
            <el-form ref="form" :model="list" label-width="160px" class="demo-ruleForm">
              <div class="form1">
                <el-form-item label="机构编号" prop="name" :style="{width:'315px'}">
                  <el-input v-model="list.id" />
                </el-form-item>
                <el-form-item label="机构名称" prop="name" :style="{width:'315px'}">
                  <el-input v-model="list.name" />
                </el-form-item>
                <el-form-item label="机构类型" prop="name" :style="{width:'315px'}">
                  <el-input v-model="form.name" />
                </el-form-item>
              </div>
              <div class="city">
                <el-form-item label="机构地址">
                  <el-select v-model="data.region" placeholder="请选择省份" :style="{width:'280px'}">
                    <el-option label="区域一" value="shanghai" />
                    <el-option label="区域二" value="beijing" />
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <el-select v-model="form.region" placeholder="请选择城市" :style="{width:'280px'}">
                    <el-option label="区域一" value="shanghai" />

                  </el-select>
                </el-form-item>
                <el-form-item>
                  <el-select v-model="form.region" placeholder="请选择区县" :style="{width:'280px'}">
                    <el-option label="区域一" value="shanghai" />
                    <el-option label="区域二" value="beijing" />
                  </el-select>
                </el-form-item>
              </div>
              <div class="form2">
                <el-form-item label="详细地址" prop="name" :style="{width:'315px'}">
                  <el-input v-model="list.address" />
                </el-form-item>
                <el-form-item label="经度" prop="name" :style="{width:'315px'}">
                  <el-input v-model="list.latitude" />
                </el-form-item>
                <el-form-item label="纬度" prop="name" :style="{width:'315px'}">
                  <el-input v-model="list.longitude" />
                </el-form-item>
              </div>
              <div class="form3">
                <el-form-item label="机构负责人" prop="name" :style="{width:'315px'}">
                  <el-input v-model="list.phone" />
                </el-form-item>
                <el-form-item label="机构电话" prop="name" :style="{width:'315px'}">
                  <el-input v-model="list.managerName" />
                </el-form-item>
              </div>
              <el-form-item>
                <el-button type="primary">立即创建</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="bottom">
          <nav class="bottom-nav">
            <h3>员工信息</h3>
          </nav>
          <div class="bottom-main">
            <div class="img">
              <template>

                <el-table
                  stripe
                  :data="tableData"
                  border
                  style="width: 100%"
                >
                  <el-table-column
                    type="index"
                    :index="indexMethod"
                    label="序号"
                    width="180"
                  />
                  <el-table-column
                    prop="userId"
                    label="员工编号"
                    width="180"
                  />
                  <el-table-column
                    prop="name"
                    label="员工姓名"
                  />
                  <el-table-column
                    prop="mobile"
                    label="手机号"
                  />
                  <el-table-column
                    prop="agency.name"
                    label="所属机构"
                  />
                  <el-table-column
                    prop="account"
                    label="系统账户"
                  />
                  <el-table-column
                    prop="stationName"
                    label="系统角色"
                  />
                  <el-table-column
                    prop="status"
                    label="账户状态"
                  />
                </el-table>
                <el-pagination
                  :v-show="{list}"
                  background
                  layout="prev, pager, next"
                  :total="totall"
                  @current-change="Hchange"
                />
              </template>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { businessHall, hall, hallid, findByAgencyId } from '@/api/user'
// import { transListToTreeData } from '@/utils/index'
export default {
  name: 'OrganizationManage',
  data() {
    return {
      // id: 1,
      totall: 5,
      hhId: 1,
      tableData: [

      ],
      form: {
        extra: '',
        id: '',
        latitude: '',
        longitude: '',
        managerName: '',
        name: '',
        parentId: '',
        phone: '',
        status: '',
        type: '',
        region: ''
      },
      page: 1,
      arr: [],
      list: [],
      data: [

      ],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  async created() {
    this.hId()
    // this.handleNodeClick()

    // this.HhID()
    const revs = await findByAgencyId({
      page: 1,
      pageSize: 5

    })
    console.log(revs.data.data.items)
    this.tableData = revs.data.data.items
  },
  methods: {
    async  HhID() {
      const res = await businessHall(this.data.id)
      console.log(res)
    },
    async  hId() {
      const res = await hall()
      this.data = JSON.parse(res.data.data)
      // console.log(this.data)
      // console.log(res)

      console.log(this.data.id)
      // this.arr = res.data.data
      // this.data = transListToTreeData(this.arr, 1)
      // console.log()
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    async handleNodeClick(data) {
      // console.log(data.id)
      // this.id = data.$treeNodeId
      // 这个是表单
      this.hhId = data.id
      const res = await hallid(this.hhId)
      // console.log(res.data.data)
      this.list = res.data.data
      console.log(res.data)
      // 这个是表格
      this.NodeClick()
      // console.log(this.tableData.length)
    },
    async NodeClick() {
      const revs = await findByAgencyId({
        page: this.page,
        pageSize: 5,
        agencyId: this.hhId

      })
      // console.log(revs.data.data.counts)
      this.totall = parseInt(revs.data.data.counts)
      console.log(this.totall)
      this.tableData = revs.data.data.items
    },
    Hchange(i) {
      // console.log(i)
      this.page = i
      this.NodeClick()
    }
  }
}
</script>
<style lang="scss" scoped>
    *{
        padding: 0;
        margin: 0;
    }
   ::v-deep .el-input__inner{
        background-color: #f5f7fa !important;
    }
    .app-container{
        display: flex;
        padding: 20px;
        .left{
            height: 800px;
            margin-right: 30px;
            background-color: #fff;
            padding: 20px 18px;
            .left-main{
               ::v-deep .el-tree-node{
                    margin-bottom: 10px;
                    width: 230px;
                }
            }
        }
        .right{
            height: 800px;
            margin-left: 20px;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            .top{
            width: 1200px;
            height: 380px;
            background-color: #fff;
                .top-nav{
                    height: 55px;
                    background-color: #fafafa;
                    font-size: 16px;
                    line-height: 55px;
                    border-bottom: 1px solid #ebeef5;
                    padding-left:18px ;
                }
                .top-main{
                    padding: 20px 15px;
                }
                .el-button{
                    width: 80px;
                    height: 35px;
                    margin-top: 40px ;
                    margin-left: 350px;
                    background-color: #e15536;
                    border: 1px solid #e15536;
                }
                .form1{
                    display: flex;
                }
                .city{
                    display: flex;
                    justify-content: flex-start;
                    margin-top:15px ;
                    .el-form-item{
                        width: 282px;
                    }
                }
                .form2{
                    display: flex;
                    margin-top:15px ;
                }
                .form3{
                    display: flex;
                     margin-top:15px ;

                }
            }
            .bottom{
            width: 1200px;
            height: 380px;
            background-color: #fff;
                .bottom-nav{
                    height: 55px;
                    background-color: #fafafa;
                    font-size: 16px;
                    line-height: 55px;
                    border-bottom: 1px solid #ebeef5;
                    padding-left:18px ;
                }
                .bottom-main{
                    .img{
                        display: flex;
                        flex-direction: column;
                        align-items: center;
                        justify-content: space-between;
                       img{
                        width: 300px;
                        height: 200px;
                       }
                    }
                }
            }
        }
    }
</style>
